

\begin{figure}
\centering
\includegraphics[scale=0.35]{img/program_flow}
\caption{Detailed program flow for the HiPerCopS IDE}
\label{fig:ProgramFlow}
\end{figure}

To demonstrate the typical workflow of the HiPerCopS IDE, consider the design and simulation of a CORDIC unit. This description will follow the steps outlined in Figure \ref{fig:ProgramFlow}, after some brief information about CORDIC units.

\section{The CORDIC Unit}

\begin{figure}
\centering
\includegraphics[scale=0.25]{img/cordic_stage}
\caption{Cordic stage flowchart.}
\label{fig:CordicStage}
\end{figure}

The CORDIC unit is a common component in digital signal processors \cite{myjak_vlsi08}. It can be configured to perform a variety of mathematical operations, including square root, division, and rectangular-to-polar conversion. Each stage of a CORDIC computation implements Equation \ref{eq:cordic}. A flowchart representing a single stage of the CORDIC unit is shown in Figure \ref{fig:CordicStage}.
\begin{eqnarray}  \label{eq:cordic}
x' &=& x \mp 2^{-i}y \nonumber \\
y' &=& y \pm 2^{-i}x \nonumber \\
z' &=& z + f(i)
\end{eqnarray}

The CORDIC unit consists of seven modules: two shifters, three adders, a sign check module, and a function lookup table. The shifters take bitstring inputs and shift them to the right by up to four bits. The adders work on two's complement data, meaning that they can perform either addition or subtraction. The sign check module determines the sign of the $z$ input and sets the adders to add or subtract, accordingly. The function lookup table implements a target function, returning the result for any given input. For this example, the function lookup table implements an arctangent calculation.

\section{Design}

The design step involves the definitions of elements and cells and the construction of the modules and the system.

\subsection{Definition}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/module/sign.module}
\end{singlespace}
}
\caption{Sign check module file, sign.module.}
\label{fig:modulefile_cordicsign}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/cell/sign.cell}
\end{singlespace}
}
\caption{Sign check cell file, sign.cell.}
\label{fig:cellfile_cordicsign}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/signpos.lut}
\end{singlespace}
}
\caption{Sign check element file, signpos.lut.}
\label{fig:elemfile_cordicsignpos}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/signneg.lut}
\end{singlespace}
}
\caption{Sign check element file, signneg.lut.}
\label{fig:elemfile_cordicsignneg}
\end{figure}

The HiPerCopS IDE library contains all of the necessary definitions for constructing the shifters and the adders. It does not define some of the structures needed for the sign check module, but this turns out to be a trivial problem based on the $z$ input. If the most significant bit of $z$ is zero, the decoder returns `00000001'. If the bit is a one, the decoder returns `11111111'. This simple truth table can be implemented as a read-only memory module, as shown in Figure \ref{fig:modulefile_cordicsign}. The memory module contains a single cell, defined in Figure \ref{fig:cellfile_cordicsign}. This cell is made up of empty elements, signpos elements (Figure \ref{fig:elemfile_cordicsignpos}), and signneg elements (Figure \ref{fig:elemfile_cordicsignneg}).

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/module/arctan.module}
\end{singlespace}
}
\caption{Arctangent function module file, arctan.module.}
\label{fig:modulefile_cordicarctan}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/cell/arctan.cell}
\end{singlespace}
}
\caption{Arctangent function cell file, arctan.cell.}
\label{fig:cellfile_cordicarctan}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/arctan0.lut}
\end{singlespace}
}
\caption{Arctangent function element file, arctan0.lut.}
\label{fig:elemfile_cordicarctan0}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/arctan1.lut}
\end{singlespace}
}
\caption{Arctangent function element file, arctan1.lut.}
\label{fig:elemfile_cordicarctan1}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/arctan2.lut}
\end{singlespace}
}
\caption{Arctangent function element file, arctan2.lut.}
\label{fig:elemfile_cordicarctan2}
\end{figure}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../lib/element/arctan3.lut}
\end{singlespace}
}
\caption{Arctangent function element file, arctan3.lut.}
\label{fig:elemfile_cordicarctan3}
\end{figure}

The arctan module is another structure that must be defined because it is not part of the default HiPerCopS IDE library. This module, defined in Figure \ref{fig:modulefile_cordicarctan}, also contains a single cell, shown in Figure \ref{fig:cellfile_cordicarctan}. The arctan cell uses four custom elements in addition to the empty element. The contents of these lookup tables are shown in Figure \ref{fig:elemfile_cordicarctan0} through Figure \ref{fig:elemfile_cordicarctan3}.

\subsection{Construction}


To create the system file, start the HiPerCopS IDE by calling the command {\tt python spoc\_gui.py}. Then, from the menu, select Systen $\rightarrow$ New System. This will open the design window. In the design window, click the left mouse button to create a node in the window. Then use the right mouse button to click on this first node. Select the {\tt set attr} option, type {\tt label=rshift} in the text box, and click the {\tt OK} button. These actions created and defined the first shifter in the system. Repeat these steps to create more nodes, labeling them with the module types required for the CORDIC unit. Use the diagram in Figure \ref{fig:CordicStage} as a guide.

To connect the nodes together, use the center mouse button to click in the middle of the source node. Then drag the mouse to the middle of the destination node and release the center mouse button. This will draw a connecting line between the two nodes. Use this method to define all of the connections in the CORDIC unit.

After this is done, right click on the canvas and select {\tt do layout}. This will rearrange the nodes and apply the labels, shown in Figure \ref{fig:dotty}. Notice that the result looks very similar to the CORDIC unit flowchart (Figure \ref{fig:CordicStage}).

\begin{figure}
  \begin{center}
    \subfigure[Before layout]{\includegraphics[scale=0.5]{img/dotty}}
    \subfigure[After layout]{\includegraphics[scale=0.5]{img/dotty_2}}
  \end{center}
  \caption{System construction}
  \label{fig:dotty}
\end{figure}

Save the system file by right-clicking on the canvas and selecting {\tt save graph as}. Name the system {\tt cordic\_system.dot} and close the editor. In the HiPerCopS menu, go to System $\rightarrow$ System from File and select the new system file. It will be displayed in the system pane of the IDE. By clicking on the Text tab, the source code behind the system graph can be inspected.

\section{Setup}

\subsection{Mapping}

Since there were no faults injected into this system, there is no need to select a mapping algorithm that avoids them. As a result, the na\"ive algorithm can be selected by choosing ``naive" under Faults $\rightarrow$ Fault Avoidance Strategy.

\subsection{Inputs and Outputs}

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../test/resources/input}
\end{singlespace}
}
\caption{Simulation input.}
\label{fig:input_csv}
\end{figure}

Construct an input file, open a text editor and follow the format shown in Figure \ref{fig:input_csv}. Save this file as input.csv.

To select the input file, go to Data $\rightarrow$ Input File. This will bring up a file selection dialog box. Navigate to your input.csv file and select it. The contents of the file will be displayed in the application's input pane.

The output file is selected under the Data $\rightarrow$ Output File menu entry. The file selection dialog box can be used to specify which file shall be overwritten by the outputs of the system. If the selected file name does not exist, it will be created.

\section{Execution}

To execute the simulation, select Execute $\rightarrow$ Run from the application menu. This will display the device map and the system outputs inside the IDE. The system outputs will also be saved to the output file specified earlier. Check the contents of that file to verify that everything worked correctly. The format of the output file will be the same as the result shown in Figure \ref{fig:output_csv}.

\begin{figure}
{\tt
\begin{singlespace}
\lstset{numbers=left, numbersep=20pt, frame=single}
\lstinputlisting{../test/resources/output}
\end{singlespace}
}
\caption{Simulation output.}
\label{fig:output_csv}
\end{figure}